{% extends "admin/admin_layout.html" %}
{% block admin_title %}管理角色权限列表{% endblock %}
{% block admin_head %}
<script type="text/javascript" src="/static/js/JsUser.js"></script>
{% endblock %}
{% set perm = request.perm_const %}
{% block admin_content %}
<div class="sect">
	<h2>“{{ this_role.name }}”角色 权限列表</h2>
    <div class="sectContent">
    	<table id="role_perm_table" class="gTable">
        	<tr>
            	<th colspan="3">
                	<input type="checkbox" autocomplete="off" id="chkAll" onclick="$checkAll('role_perm_table','chkAll');" />&nbsp;选择全部
                </th>
            </tr>
            <tr>
            {% for obj in all_perms %}
                <td><p><b>{{ obj.name }}</b></p>
                	<p> {% set ops = obj.getOps() %}
                		{% for op in ops %}
                			<input type="checkbox" autocomplete="off" value="{{ obj.id*10000+op.id }}"  id="chk_{{ obj.id*10000+op.id }}" 
                			{% if (obj.id,op.id) in this_perms %} checked="true"{% endif %} />{{op.name}}
                		{% endfor %}
                	</p>
                </td>
                {% if loop.index % 3 == 0%}</tr><tr>{% endif %}
            {% endfor %}
            </tr>
        </table>
        <div class="setCenter">
        	{% if perm.check_perm_op(perm.perm_role,perm.op_change) %}
        	<input type="button" class="buttonLarge" value="确定" onclick="submit_role_perm('role_perm_table','chkAll','{{ this_role.id }}');" />
        	{% endif %}
        	<p id="role_perm_err" class="alert"></p>
        </div>
    </div>
</div>
<script type="text/javascript">
function submit_role_perm(parent, chkall, role_id){
    var ptable = $(parent);var permids = "";
    var childs = ptable.getElementsByTagName("input");
    for (var i = 0; i < childs.length; i++) {if (childs[i].checked && childs[i].id != chkall) {permids += childs[i].value + ",";}}
    if (!permids) {new MsgBox({message:"没有选中任何权限"});return;}
    var params = "value=" + String.encode(permids);
    new echoAjax({url:"/admin/role/" + role_id + "/perm/update/", params:params,reLoad:true,message:{success:'操作成功'}}).fire();
}
</script>
{% endblock %}
